package com.shoeshopping.utils.zx;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.shoeshopping.entity.Admin;

public class HttpSessionUtil {
	private HttpSessionUtil(){
		
	}
	
	public static final String ADMIN_ID = "amdinId";
	public static final String ADMIN_USERNAME = "amdinUsername";
	
	private static HttpSessionUtil httpSessionUtil = null;
	
	public static HttpSessionUtil shareHttpSessionUtil(){
		if(httpSessionUtil == null){
			httpSessionUtil = new HttpSessionUtil();
		}
		return httpSessionUtil;
	}
	
	public void addAdmin(Admin admin){
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.put(ADMIN_ID, admin.getId());
		session.put(ADMIN_USERNAME, admin.getUsername());
	}
	
	public void removeAdmin(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.remove(ADMIN_ID);
		session.remove(ADMIN_USERNAME);
	}
	
	public String getAdminId(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		return (String) session.get(ADMIN_ID);
	}
}
